<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8">
		<title>MVC DOH Search Results Repeat Test</title>
		<style>
			@import "../../../../../dojo/resources/dojo.css";
			@import "../../../../../dijit/tests/css/dijitTests.css";
			@import "../../css/app-format.css";
		</style>
		<link id="themeStyles" rel="stylesheet" href="../../../../../dijit/themes/claro/claro.css"/>
<!--  <script src="../../../dojo/dojo.js" type="text/javascript" data-dojo-config="isDebug: true"></script> -->		
	<script type="text/javascript">
		require = {
			isDebug: 1,
			async: 1
		};
	</script>

	<!-- required: dojo.js -->
	<script type="text/javascript" src="../../../../../dojo/dojo.js"></script>

		<script type="text/javascript" src="../helpers.js"></script>
		<script type="text/javascript">

			require([
				"doh/runner",
				"dojo/parser",
			//	"dojox/mobile/parser",
				"dijit/registry",
				"dojox/mvc/at",
				"dojox/mvc/getStateful",
				"dojo/store/Memory",
				"dojox/mvc/EditStoreRefListController",
				"dojo/dom",
				"dojo/store/Observable",
				"dijit/form/Button",
				"dijit/form/TextBox",
				"dojox/mvc/_atBindingExtension",
				"dojox/mvc/ListController",
				"dojox/mvc/StatefulArray",
				"dojox/mvc/Group",
				"dojox/mvc/Output",
				"dojox/mvc/WidgetList",
				"dojox/mvc/_InlineTemplateMixin",
				"dojo/domReady!"
			], function(doh, parser, registry, at, getStateful, Memory, EditStoreRefListController, dom){
				function runTests(){
					// should be able to verify all of the inputs 
					doh.register("parse", [
						{
							name: "parse",
							runTest: function(){
								console.log("in parse test with maxentries ="+maxentries);
								parser.parse(dom.byId("stateful"));
							}
						}
					]);
					doh.register("parse2", [
											{
												name: "parse",
												runTest: function(){
													ctrl = new EditStoreRefListController({store: new Memory({data: data2})});
													ctrl.queryStore();
													
													console.log("in ctrl parse test with maxentries ="+maxentries);
													parser.parse(dom.byId("ctrl"));
												}
											}
										]);


					doh.run();
				}

				window.at = at;

				//parser.parse();

				setDetailsContext = function(index){
					var ctl = registry.byId("listCtl");
					ctl.set("cursorIndex", index);
				};

				var data = [
							{
								id: "1",
								Group: "Engineer",
								First: "Anne",
								Last: "Ackerman",
								Location: "NY",
								Office: "1S76",
								Email: "a.a@test.com",
								Tel: "123-764-8237",
								Fax: "123-764-8228"
							},
							{
								id: "2",
								Group: "Engineer",
								First: "Ben",
								Last : "Beckham",
								Location: "NY",
								Office: "5N47",
								Email: "b.b@test.com",
								Tel: "123-764-8599",
								Fax: "123-764-8600"
							},
							{
								id: "3",
								Group: "Engineer",
								First: "Chad",
								Last: "Chapman",
								Location: "CA",
								Office: "1278",
								Email: "c.c@test.com",
								Tel: "408-764-8237",
								Fax: "408-764-8228"
							},
							{
								id: "4",
								Group: "Engineer",
								First: "David",
								Last: "Durham",
								Location: "NJ",
								Office: "C12",
								Email: "d.d@test.com",
								Tel: "514-764-8237",
								Fax: "514-764-8228"
							},
							{
								id: "5",
								Group: "Engineer",
								First: "Emma",
								Last: "Eklof",
								Location: "NY",
								Office: "4N76",
								Email: "e.e@test.com",
								Tel: "123-764-1234",
								Fax: "123-764-4321"
							},
							{
								id: "6",
								Group: "Manager",
								First: "Fred",
								Last: "Fisher",
								Location: "NJ",
								Office: "V89",
								Email: "f.f@test.com",
								Tel: "514-764-8567",
								Fax: "514-764-8000"
							},
							{
								id: "7",
								Group: "Manager",
								First: "George",
								Last: "Garnett",
								Location: "NY",
								Office: "7S11",
								Email: "gig@test.com",
								Tel: "123-999-8599",
								Fax: "123-999-8600"
							},
							{
								id: "8",
								Group: "Accountant",
								First: "Hunter",
								Last: "Huffman",
								Location: "CA",
								Office: "6532",
								Email: "h.h@test.com",
								Tel: "408-874-8237",
								Fax: "408-874-8228"
							},
							{
								id: "9",
								Group: "Accountant",
								First: "Irene",
								Last: "Ira",
								Location: "NJ",
								Office: "F09",
								Email: "i.i@test.com",
								Tel: "514-764-6532",
								Fax: "514-764-7300"
							},
							{
								id: "10",
								Group: "Accountant",
								First: "John",
								Last: "Jacklin",
								Location: "CA",
								Office: "6701",
								Email: "j.j@test.com",
								Tel: "408-764-1234",
								Fax: "408-764-4321"
							}
						];
						window.ctrl = null;
						var data2 = data;
						var currentId = 10;
						maxentries = 100;
						for(var a = data2, i = 0; i < maxentries; i++){
							var d = 				{
									id: currentId++,
									Group: "Engineer",
									First: "First"+currentId,
									Last: "Last"+currentId,
									Location: "CA",
									Office: "6701",
									Email: "j.j@test.com"+currentId,
									Tel: "408-764-1234",
									Fax: "408-764-4321"
								};
							data2.push(d);				
						}
				searchRecords = {};
				searchRecords.Results = getStateful(data2);

				runTests();

			});
		</script>
	</head>
<body class="claro" style="width:100%;height:100%;margin:0;padding:0;">
		<div id="header">
		  <div id="navigation">
		  </div>
		  <div id="headerInsert">
			<h1>Employee Search</h1>
			<h2>Master Detail Example - With repeat container.</h2>
		  </div>
		</div>
		<div id="main">
		 <div id="leftNav"></div>
		 <div id="mainContent">
	   	 <div  id="ctrl"> 	
			<div id="repeat1"
				data-dojo-type="dojox/mvc/WidgetList"
				data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
				data-dojo-props="children: at(ctrl, 'model')">
				<script type="dojox/mvc/InlineTemplate">
					<div class="row">
						<label class="cell" for="xnameInput${indexAtStartup}">Name:</label>
						<input class="cell" data-dojo-type="dijit.form.TextBox" id="xnameInput${indexAtStartup}"
						 data-dojo-props="value: at('rel:', 'First')">
						<button type="button" data-dojo-type="dijit.form.Button"
						 data-dojo-props="onClick: function(){ ctrl.set('cursorIndex', ${indexAtStartup}); }">Details</button>
						<button type="button" data-dojo-type="dijit.form.Button"
						 data-dojo-props="onClick: function(){ ctrl.addEmpty(); }">+</button>
						<button type="button" data-dojo-type="dijit.form.Button"
						 data-dojo-props="onClick: function(){ ctrl.remove(${indexAtStartup}); }">-</button>
					</div>
				</script>
			</div>
		</div>
		 
	   	 <div  id="stateful"> 	
			<div id="searchBanner">Search Results for term: Engineers</div>
			<div data-dojo-type="dojox/mvc/WidgetList"
				data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
				data-dojo-props="children: at('searchRecords', 'Results')">
				<script type="dojox/mvc/InlineTemplate">
					<div class="row">
						<label class="cell" for="ynameInput${indexAtStartup}">Name:</label>
						<input class="cell" data-dojo-type="dijit.form.TextBox" id="ynameInput${indexAtStartup}"
						 data-dojo-props="value: at('rel:', 'First')">
						<button type="button" data-dojo-type="dijit.form.Button"
						 data-dojo-props="onClick: function(){ ctrl.set('cursorIndex', ${indexAtStartup}); }">Details</button>
						<button type="button" data-dojo-type="dijit.form.Button"
						 data-dojo-props="onClick: function(){ ctrl.addEmpty(); }">+</button>
						<button type="button" data-dojo-type="dijit.form.Button"
						 data-dojo-props="onClick: function(){ ctrl.remove(${indexAtStartup}); }">-</button>
					</div>
				</script>
			</div>
			<div class="spacer"></div>

			<div data-dojo-type="dojox.mvc.Group" 
								data-dojo-props="target: at('widget:listCtl', 'cursor')">
				<div class="row">
					<div style="display: inline-block;" id="detailsBanner">Details for result index: </div>
					<span class="cell" id="indexOutput" data-dojo-type="dojox.mvc.Output" 
							data-dojo-props="value: at('widget:listCtl', 'cursorIndex')"></span>
				</div>
				<div class="row">
					<label class="cell" for="firstInput">First Name:</label>
					<input class="cell" id="firstInput" data-dojo-type="dijit.form.TextBox" 
										data-dojo-props="value: at('rel:', 'First')">
				</div>
				<div class="row">
					<label class="cell" for="lastInput">Last Name:</label>
					<input class="cell" id="lastInput" data-dojo-type="dijit.form.TextBox" 
									data-dojo-props="value: at('rel:', 'Last')">
				</div>
				<div class="row">
					<label class="cell" for="locationInput">Location:</label>
					<input class="cell" id="locationInput" data-dojo-type="dijit.form.TextBox" 
									data-dojo-props="value: at('rel:', 'Location')">
				</div>
				<div class="row">
					<label class="cell" for="officeInput">Office:</label>
					<input class="cell" id="officeInput" data-dojo-type="dijit.form.TextBox" 
									data-dojo-props="value: at('rel:', 'Office')">
				</div>
				<div class="row">
					<label class="cell" for="emailInput">Email:</label>
					<input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" 
									data-dojo-props="value: at('rel:', 'Email')">
				</div>
				<div class="row">
					<label class="cell" for="telInput">Telephone:</label>
					<input class="cell" id="telInput" data-dojo-type="dijit.form.TextBox" 
									data-dojo-props="value: at('rel:', 'Tel')">
				</div>
				<div class="row">
					<label class="cell" for="faxInput">Fax:</label>
					<input class="cell" id="faxInput" data-dojo-type="dijit.form.TextBox" 
								data-dojo-props="value: at('rel:', 'Fax')">
				</div>
			</div>
		   </div>
		 </div>
		</div>
</body>
</html>
